package com.feiniu.api.controller;

import java.util.List;

import com.feiniu.api.pojo.HttpClientResponsePojo;
import com.feiniu.api.service.TestServiceIn;

import com.feiniu.api.util.IoUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.feiniu.api.pojo.TestPojo;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;

@Component
@Path("/test")
public class TestController {
	private static final Logger LOGGER = LoggerFactory.getLogger(TestController.class);

	@Autowired
	private TestServiceIn testServiceIn;

	@POST
	@Path("/query")
	public String query(@Context HttpServletRequest request) {
		LOGGER.info("***** TestController -> query *****");

		String reqStr = IoUtil.getPostBody(request);
		LOGGER.info("request : " + reqStr);

		List<TestPojo> list = testServiceIn.query(1, 10);
		HttpClientResponsePojo response = new HttpClientResponsePojo();
		response.setCode(200);
		response.setMessage(JSON.toJSONString(list));
		LOGGER.info("response : " + JSON.toJSONString(response));
		return JSON.toJSONString(response);
	}

}
